package com.tool_stdy.thread;

import java.util.concurrent.atomic.AtomicIntegerArray;

public class TestAtoimIntegerArrayDemo implements Runnable {
	private static final AtomicIntegerArray array = new AtomicIntegerArray(10);

	@Override
	public void run() {
		for (int i = 0; i < 100000; i++) {
			array.getAndIncrement(i % array.length());
		}
	}

	public static void main(String[] args) throws InterruptedException {
		Thread[] ts = new Thread[9];
		for (int j = 0; j < 9; j++) {
			ts[j] = new Thread(new TestAtoimIntegerArrayDemo());
		}
		for (int i = 0; i < 9; i++) {
			ts[i].start();
		}
		for (int i = 0; i < 9; i++) {
			ts[i].join();
		}
		
		System.out.println(array);
	}
}
